package server

import (
	"company_website/src/global"
	"company_website/src/model"
	"company_website/src/model/common"
	"company_website/src/model/response"
)

type Item struct {
}

// GetAllItemInfoPage 分页查找所有用户
func (i *Item) GetAllItemInfoPage(reqInfo *common.GetPageInfo) (*response.GetAllItem, error) {
	resInfo := &response.GetAllItem{}
	var items []*model.Item
	var err error
	db := global.GVL_DB.Model(&model.Item{})
	resInfo.PageInfo, err = ServerComment.GetPageRes(reqInfo.Page, db)
	if err != nil {
		return nil, err
	}
	resInfo.PageInfo.PageReqInfo = reqInfo.Page
	db = ServerComment.Paginate(reqInfo.Page, db)
	err = db.Order("id desc").Find(&items).Error
	if err != nil {
		return nil, err
	}
	resInfo.ItemInfo = items
	return resInfo, nil
}
